package org.akomantoso.core.data;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.akomantoso.core.io.Externalizable;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.util.AmendmentsElementUtil;

/**
 * The complex type Amendments is a list of all the amendment elements that can be used on a document analysis.
 * 
 * <pre>
 * 	<xsd:complexType name="Amendments">
 * 		<xsd:choice minOccurs="1" maxOccurs="unbounded">
 * 			<xsd:element ref="textualMod" />
 * 			<xsd:element ref="meaningMod" />
 * 			<xsd:element ref="scopeMod" />
 * 			<xsd:element ref="forceMod" />
 * 			<xsd:element ref="efficacyMod" />
 * 			<xsd:element ref="legalSystemMod" />
 * 		</xsd:choice>
 * 	</xsd:complexType>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 */
public abstract class Amendments implements Externalizable{
	
	// Mandatory (min 1).
	private final List<AmendmentsElement> _elements = new ArrayList<AmendmentsElement>();

	public List<AmendmentsElement> getElements() {
		return _elements;
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#writeExternal(org.akomantoso.core.io.Output)
	 */
	public <T extends Output> void writeExternal(T out) throws IOException {
		for (int i = 0, n = _elements.size(); i < n; i++) {
			_elements.get(i).writeExternal(out);
		}
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#readExternal(org.akomantoso.core.io.Input)
	 */
	public <T extends Input> void readExternal(T in) throws IOException {
		AmendmentsElementUtil.read(in, _elements);
	}
	
}